package com.liuche.homechat.common.user.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.liuche.homechat.common.user.dao.UserRoleDao;
import com.liuche.homechat.common.user.domain.entity.UserRole;
import com.liuche.homechat.common.user.enums.RoleEnum;
import com.liuche.homechat.common.user.service.UserRoleService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @author：liuche
 * @Date：2024年06月08日 17:18
 * @Description：
 */
@Slf4j
@Service
public class UserRoleServiceImpl implements UserRoleService {
    @Resource
    private UserRoleDao userRoleDao;
    @Override
    public void genCommonRole(Long uid) {
        UserRole userRole = UserRole.builder()
                .roleId(RoleEnum.COMMON_USER.getId())
                .uid(uid)
                .build();
        userRoleDao.save(userRole);
    }

    @Override
    public UserRole queryUserRoleByUid(Long uid) {
        LambdaQueryWrapper<UserRole> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(UserRole::getUid, uid);

        return userRoleDao.getOne(queryWrapper);
    }
}
